package com.android.common.network;

import android.util.Log;
import androidx.annotation.NonNull;
import com.android.common.BuildConfig;
import com.android.common.constant.Constant;
import com.android.common.utils.SpUtils;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class RequestInterceptor implements Interceptor {

    public static final String TAG = "RetrofitManager";

    @NonNull
    @Override
    public Response intercept(@NonNull Chain chain) throws IOException {
        Request original = chain.request();
        String token = SpUtils.getString(Constant.TOKEN_KEY);
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "token = " + token);
        }
        //可以在此配置统一的头信息
        Request request = original.newBuilder()
            .header(Constant.TOKEN_KEY, token)
            .build();

        return chain.proceed(request);
    }
}
